//
//  HSXViewController.swift
//  PassValueDemo
//
//  Created by MAC on 2020/8/20.
//  Copyright © 2020 MAC. All rights reserved.
//

import UIKit

class HSXViewController: UIViewController {
    
    var textF = UITextField()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //传值按钮
        let ymBtn_01 = UIButton()
        ymBtn_01.frame = CGRect(x: 50, y: 130, width: 220, height: 50)
        ymBtn_01.setTitle("跳转发送传值页面", for: .normal)
        ymBtn_01.backgroundColor = .brown
        ymBtn_01.tag = 10001
        ymBtn_01.addTarget(self, action: #selector(tiaozhuanyemianclick(sender:)), for: .touchUpInside)
        view.addSubview(ymBtn_01)
        
        //传值的输入框
        textF.frame = CGRect(x: 50, y: (ymBtn_01.frame.origin.y + ymBtn_01.frame.size.height) + 50, width: view.frame.size.width - 100, height: 50)
        textF.attributedPlaceholder = NSAttributedString(string: "请输入要传的值", attributes: [NSAttributedString.Key.foregroundColor : UIColor.yellow])
        textF.borderStyle = .line
        textF.textColor = .white
        textF.backgroundColor = .darkGray
        view.addSubview(textF)
    }
    //实现传值按钮的监听方法
    @objc func tiaozhuanyemianclick(sender:UIButton){
        
        let aSXVC = ASXViewController()
        aSXVC.myStr = textF.text!
        aSXVC.view.backgroundColor = .white
        //属性传值 - string
        aSXVC.title = "接收属性传值"
        /*
         如果不在输入框内填写想要传的值，那么下面的数组也可以实现属性传值
         数组，不会显示在页面上，但可以在下面控制台里打印出来
         */
        //属性传值 - Array
        let arrs:Array = ["宝马", "奔驰", "奥迪", "兰博基尼", "凯迪拉克", "法拉利"]
        //拷贝数组
        for item in arrs {
            aSXVC.arr.append(item)
        }
        /*
         属性传值 - 实例方法
         调用：在上级界面中，通过class名去调内部方法名
          class.方法名()
         */
        aSXVC.counter.increment(amount: 10203020301005060)
        
        //开始跳转界面
        self.navigationController?.pushViewController(aSXVC, animated: true)
    }
}
